<template>
  <!-- <p>{{ data.name }} - {{ data.manager }}</p> -->
  <!-- tree子节点的宽度默认由内容撑开,  -->
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width: 100%">
    <el-col :span="20">
      <span>{{ nodedata.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodedata.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="del">删除部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="edit">编辑部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { reqDeldepartment } from '@/api/department'
export default {
  props: {
    nodedata: {
      type: Object,
      required: true
    },
    root: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // del() {
    //   console.log('shanchule')
    // },
    handleCommand(type) {
      // console.log('有菜单被点击了', type)
      if (type === 'add') {
        // console.log('添加的逻辑')
        // this.nodedata新增的父级部门
        this.$emit('addDept', this.nodedata)
      }
      if (type === 'del') {
        // console.log('删除的逻辑')
        this.$confirm('此操作将永久删除该部门,是否继续', '温馨提示')
          .then(async() => {
            await reqDeldepartment(this.nodedata.id)
            this.$message.success('删除成功')
            this.$emit('del-depts')
          }).catch(() => {
            console.log('取消')
          })
      }
      if (type === 'edit') {
        // console.log('编辑的逻辑')
        this.$emit('edit-dept', this.nodedata)
      }
    }
  }
}
</script>

<style>

</style>
